package com.zking.dao;

import com.zking.entity.News;
import com.zking.entity.View;

import com.zking.util.DBUtil;

import java.sql.PseudoColumnUsage;
import java.util.List;

// function
public class ViewDao {
    public static List<View> getNewsByPage(int pageIndex, int pageSize) {
        String sql = "select * from easybuy_view limit ?,?";
        return DBUtil.query(sql, View.class,(pageIndex-1)*pageSize,pageSize);
    }
    public static int getMaxPage(int pageSize) {
        List<View> list = getAllView();
        int total = list.size();
        int maxPage = total/pageSize;
        if(total%pageSize!=0){
            maxPage++;
        }
        return maxPage;
    }
    //从数据库获取数据
    public static List<View> getAllView() {
        String sql = "select * from easybuy_view";
        return DBUtil.query(sql, View.class);
    }

    public static boolean deleteViews(Integer id) {
        System.out.println("进入删除");
        String sql = "delete from easybuy_view where uuid=?";
        return DBUtil.update(sql,id);
    }

    //更新留言本信息
    public static boolean updateViews(String review,Integer uuid) {
        String sql = "update easybuy_view set review=? where uuid=?";
        return DBUtil.update(sql,review,uuid);
    }
    public static boolean addViews(View view)
    {
        String sql = "INSERT INTO easybuy_view (content, review, time, name, id) VALUES (?, ?, ?, ?, ?)";
        return DBUtil.update(sql, view.getContent(), view.getReview(), view.getTime(), view.getName(), view.getId());
    }



}
